package com.api.weavernorth.shortAddress;


import com.alibaba.fastjson.JSONObject;
import com.weavernorth.util.GetShortUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.general.Util;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;


/**
 * @program: ecology_erdos
 * @description:
 * @author: zm
 * @create: 2019-11-05 10:57
 **/
@Path("/weavernorth/shortAddress")
public class GetShortAddress extends HttpServlet {
    public static Log log = LogFactory.getLog(GetShortAddress.class.getName());

    @GET
    @Path("/getAddress")
    @Produces(MediaType.TEXT_PLAIN)
    public String getAddress(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        GetShortUtil getShortUtil=new GetShortUtil();
        //获取个人电话号
        String strGrdh=Util.null2String(request.getParameter("grdhVal"));
        //返回地址
        String strShortAddress="";
        try {
            //拼接请求地址
            //String strAddress="http://tsu.im/api/v1/sUrl?type=json&url=http://oa.chinaerdos.com/weavernorth/writeMess.jsp?phone="+strGrdh;
            String strAddress = "http://tsu.im/api/v1/sUrl?type=json&url=http://testoa.chinaerdos.com:8081/weavernorth/writeMess.jsp?phone=" + strGrdh;
            log.info("请求参数:" + strAddress);
          String strReturn= getShortUtil.senDealPost(strAddress);
          log.info("返回数据:"+strReturn);
          if(!"".equals(strReturn)){
              JSONObject jsonObject=JSONObject.parseObject(strReturn);
              //标识
              boolean strRet=jsonObject.getBoolean("ret");
              log.info("返回标识:"+strRet);
              if(strRet){
                   strShortAddress=jsonObject.getString("data");
                   log.info("返回的短地址:"+strShortAddress);
              }

          }
        }catch (Exception e){
            e.printStackTrace();
        }


        return strShortAddress;
    }


}
